//
//  ViewController.m
//  17-HomeWork
//
//  Created by dllo on 16/8/5.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    /** 实现文件、文件夹的基本操作(调研NSFileManager, 并实现以下功能)
     创建文件、文件夹
     删除文件、文件夹
     文件 是否存在
     移动文件
     拷贝文件
     */
//    1>创建文件、文件夹
  //获取Docments路径
    NSArray *doucMententPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// 获取libarary的路径
    NSArray *libraryPath = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSFileManager *fileManager = [NSFileManager defaultManager];
//    myFile路径
    NSString *myFilePath = [[doucMententPath firstObject] stringByAppendingPathComponent:@"myFile"];
//  创建文件夹
    NSError *error = nil;
  BOOL isCreateFileSuccess = [fileManager createDirectoryAtPath:myFilePath withIntermediateDirectories:YES attributes:nil error:&error];
    if (isCreateFileSuccess) {
        NSLog(@"创建文件夹成功");
    } else {
        NSLog(@"创建文件夹失败");
    }
  //创建文件
    NSArray *fileArray = @[@"1",@"2"];
    NSString *fileArrayPath = [myFilePath stringByAppendingPathComponent:@"fileArray.plist"];
   BOOL isCreateFileArraySuccess = [fileArray writeToFile:fileArrayPath atomically:YES];
    if (isCreateFileArraySuccess) {
        NSLog(@"创建文件成功");
    } else {
        NSLog(@"创建文件失败");
    }
//    2>文件 是否存在
  BOOL isExists = [fileManager fileExistsAtPath:fileArrayPath];
    if (isExists) {
        NSLog(@"文件存在");
    } else {
         NSLog(@"文件不存在");
    }
//     3> 移动文件
//    需要移动的路径
    NSString *newFileArrayPath = [[libraryPath firstObject] stringByAppendingString:@"/fileArray.plist"];
    BOOL isMoveSuccess = [fileManager moveItemAtPath:fileArrayPath toPath:newFileArrayPath error:nil];
    if (isMoveSuccess) {
        NSLog(@"移动成功");
    } else {
        NSLog(@"移动失败");

    }
//    4> 删除文件
  BOOL isRemoveSuccess = [fileManager removeItemAtPath:newFileArrayPath error:nil];
    if (isRemoveSuccess) {
        NSLog(@"删除成功");
    } else {
        NSLog(@"删除失败");
    }
//   5> 拷贝文件
  // 拷贝文件到指定路径
    
  BOOL isCpoySuccess = [fileManager copyItemAtPath:newFileArrayPath toPath:NSHomeDirectory() error:nil];
    if (isCpoySuccess) {
         NSLog(@"拷贝成功");
    }else {
        NSLog(@"拷贝失败");
 
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
